package org.example;

public class Demo3 {
    public static void main(String[] args) {

        // 分配一定数量的小对象以观察GC行为
        for (int i = 0; i < 50; i++) {
            byte[] b = new byte[1024000];  // 分配1KB的对象 *1000
            printMemery();
        }


    }

    private static void printMemery() {
        String buffer = "最大堆内存: " + Runtime.getRuntime().maxMemory() / 1024 / 1024 + "MB\t" +
                "当前堆内存总量: " + Runtime.getRuntime().totalMemory() / 1024 / 1024 + "MB\t" +
                "空闲内存: " + Runtime.getRuntime().freeMemory() / 1024 / 1024 + "MB";
        System.out.println(buffer);
    }


    private void ff() {
        int sizeM = 1024 * 1024;
        byte[] bytes1 = new byte[3 * sizeM];
        byte[] bytes2 = new byte[3 * sizeM];
        byte[] bytes3 = new byte[3 * sizeM];
        //byte[] bytes4 = new byte[2 * sizeM];
    }
}
